import api from '../../api/api'

import { getUserInfo} from '../../api/conf'

const orderTagInfos = [
  {
    title: '待付款',
    iconName: 'wallet',
    orderNum: 0,
    tabType: 5,
    status: 1,
    prefix: 'wr'
  },
  {
    title: '待发货',
    iconName: 'package',
    orderNum: 0,
    tabType: 10,
    status: 1,
    prefix: 'wr'
  },
  {
    title: '待收货',
    iconName: 'deliver',
    orderNum: 0,
    tabType: 40,
    status: 1,
    prefix: 'wr'
  },
  {
    title: '已完成',
    iconName: 'fact-check',
    orderNum: 0,
    tabType: 60,
    status: 1,
    prefix: 't-icon'
  },
  {
    title: '退款/售后',
    iconName: 'exchang',
    orderNum: 0,
    tabType: 0,
    status: 1,
    prefix: 'wr'
  },
];

const menuData = [
  [
    {
      title: '收货地址',
      tit: '',
      url: '',
      type: 'address',
    },
    {
      title: '优惠券',
      tit: '',
      url: '',
      type: 'coupon',
    },
    {
      title: '蟹卡兑换',
      tit: '',
      url: '',
      type: 'giftCard',
    }
  ],
  [
    {
      title: '联系客服',
      tit: '',
      url: '',
      type: 'service',
      icon: 'service'
    },
    {
      title: '购买须知',
      tit: '',
      url: '',
      type: 'serviceProtocol',
    },
    {
      title: '关于我们',
      tit: '',
      url: '',
      type: 'abouts',
    },
  ]
];


Page({
  data: {
    avatarUrl: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
    nickName: '微信用户',
    menuData,
    orderTagInfos,
    customerServiceInfo: api.customerServiceInfo,
    showMakePhone: false,
    showKefu: true,
  },
  onLoad: function(options) {

  },
  onShow: function () {
    this.getTabBar().init();
    this.getUserData()
  },
  getUserData: function () {
    const timestamp = new Date ().getTime ();
    wx.showNavigationBarLoading()
    api.get(getUserInfo, {
    }).then(res => {
      this.setData({
        avatarUrl: res.Data.AvatarUrl?res.Data.AvatarUrl+'?time='+timestamp:this.data.avatarUrl,
        nickName: res.Data.Nickname?res.Data.Nickname:'微信用户',
      })
      wx.hideNavigationBarLoading()
    })
  },
  jumpAllOrder: function () {
    wx.navigateTo({ url: '/pages/order/order' });
  },
  jumpNav: function () {
    
  },
  onClickCell: function ({currentTarget}) {
    const { type } = currentTarget.dataset;
    switch (type) {
      case 'address':
        wx.navigateTo({ url: '/pages/address/address' });
        break;

      case 'coupon':
        wx.navigateTo({ url: '/pages/coupon/coupon?couponType=1' });
        break;

      case 'giftCard':
        // wx.navigateTo({ url: '/pages/coupon/coupon?couponType=1' });
        break;

      case 'serviceProtocol':
        wx.navigateTo({ url: '/pages/question/question?name=serviceProtocol' });
        break;

      case 'abouts':
        wx.navigateTo({ url: '/pages/question/question?name=aboutus' });
        break;

      case 'service': {
        this.openMakePhone();
        break;
      }
    }
  },
  getUserInfo: function (){
    wx.navigateTo({
      url: '/pages/user/user'
    })
  },

  call() {
    wx.makePhoneCall({
      phoneNumber: this.data.customerServiceInfo.servicePhone,
    });
  },

  openMakePhone() {
    this.setData({ showMakePhone: true });
  },

  closeMakePhone() {
    this.setData({ showMakePhone: false });
  },
})